package com.ruoyi.stateMachineDemo.config;

import com.ruoyi.stateMachineDemo.States;
import org.springframework.statemachine.annotation.OnTransition;
import org.springframework.statemachine.annotation.OnTransitionEnd;
import org.springframework.statemachine.annotation.OnTransitionStart;
import org.springframework.statemachine.annotation.WithStateMachine;

@WithStateMachine
public class EventConfig {

    @OnTransition(target = "UNPAID")
    public void create() {
        System.out.println("订单创建，待支付");
    }
    @OnTransition(source = "UNPAID",target = "WAITING_FOR_RECEIVE")
    public void pay(){
        System.out.println("用户完成支付，待收货");
    }
    @OnTransitionStart(source = "UNPAID",target = "WAITING_FOR_RECEIVE")
    public int payStart(){
        System.out.println("用户完成支付，支付--开始");
        return States.UNPAID.getValue();
    }
    @OnTransitionEnd(source = "UNPAID",target = "WAITING_FOR_RECEIVE")
    public int payEnd(){
        System.out.println("用户完成支付，支付--结束");
        return States.WAITING_FOR_RECEIVE.getValue();
    }
    @OnTransition(source = "WAITING_FOR_RECEIVE",target = "DONE")
    public void receive(){
        System.out.println("用户已收货，订单完成");
    }


}
